#include "flash-memory.h"
#include "exceptions.h"

FlashMemory::FlashMemory (uint16_t size, uint16_t address_base)
  : DataBusMember (address_base)
{
  /* Unset the LSB of size to ensure it's even */
  _size = size & (uint16_t)~0x1;
  _data = new uint16_t[_size / 2];
}

FlashMemory::~FlashMemory ()
{
  delete [] _data;
}

void FlashMemory::clock_tick ()
{
}

uint16_t FlashMemory::operator[] (uint16_t address) const
{
  if (address >= _size)
    throw MemoryException (address);

  return _data[address];
}

uint16_t& FlashMemory::operator[] (uint16_t address)
{
  if (address >= _size)
    throw MemoryException (address);

  return _data[address];
}
